#include <iostream>
#include "Bundle.h"

using namespace std;
using android::Bundle;
using android::Parcel;

void output(const Bundle& a)
{
    cout << "Int8:\t\t" << (int)a.getInt8("Int8") << endl;
    cout << "Int16:\t\t" << a.getInt16("Int16") << endl;
    cout << "Int32:\t\t" << a.getInt32("Int32") << endl;
    cout << "Int64:\t\t" << a.getInt64("Int64") << endl;
    cout << "Float:\t\t" << a.getFloat("Float") << endl;
    cout << "Double:\t\t" << a.getDouble("Double") << endl;
    cout << "String:\t\t" << a.getString("String") << endl;

    cout << "Int8Vector:\t{ ";
    for (const auto& v : a.getInt8Vector("Int8Vector")) {
        cout << (int)v << ", ";
    }
    cout << "}\n";

    cout << "Int16Vector:\t{ ";
    for (const auto& v : a.getInt16Vector("Int16Vector")) {
        cout << v << ", ";
    }
    cout << "}\n";

    cout << "Int32Vector:\t{ ";
    for (const auto& v : a.getInt32Vector("Int32Vector")) {
        cout << v << ", ";
    }
    cout << "}\n";

    cout << "Int64Vector:\t{ ";
    for (const auto& v : a.getInt64Vector("Int64Vector")) {
        cout << v << ", ";
    }
    cout << "}\n";

    cout << "FloatVector:\t{ ";
    for (const auto& v : a.getFloatVector("FloatVector")) {
        cout << v << ", ";
    }
    cout << "}\n";

    cout << "DoubleVector:\t{ ";
    for (const auto& v : a.getDoubleVector("DoubleVector")) {
        cout << v << ", ";
    }
    cout << "}\n";

    cout << "StringVector:\t{ ";
    for (const auto& v : a.getStringVector("StringVector")) {
        cout << v << ", ";
    }
    cout << "}\n";
}

int main()
{
    // 构建不同类型的key-value
    Bundle a;
    a.putInt8("Int8", 123)
        .putInt16("Int16", 10086)
        .putInt32("Int32", 123456789)
        .putInt64("Int64", 987654321123456LL)
        .putFloat("Float", 10010.f)
        .putDouble("Double", 9876543211234.0)
        .putString("String", "I'm Kehuadong!!!")
        .putInt8Vector("Int8Vector", { 123, -123 })
        .putInt16Vector("Int16Vector", { 10086, 10000 })
        .putInt32Vector("Int32Vector", { 123456789, 987654321 })
        .putInt64Vector("Int64Vector", { 987654321123456LL, 654132657986354LL })
        .putFloatVector("FloatVector", { 10010.f, 8086.f })
        .putDoubleVector("DoubleVector", { 9876543211234.0, 789456321654.0 })
        .putStringVector("StringVector", { "I'm Kehuadong!!!", "Who are You?" });

    // 序列化
    Parcel parcel;
    a.writeToParcel(&parcel);

    // 反序列化
    Bundle b;
    b.readFromParcel(&parcel);

    // 打印对比a,b
    output(a);
    cout << "\n----------------------------------------------------------\n\n";
    output(b);

    return 0;
}